/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* includes (local) ----------------------------------------------------------*/
#include <bsp_psram.h>
/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_config.h>
#include <x_module.h>

#include <m_heap.h>

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* variables (extern) --------------------------------------------------------*/

/* variables (local) ---------------------------------------------------------*/
/* variables (global) --------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* functions -----------------------------------------------------------------*/

#if !defined(CONFIG_LLT)

static int __drv_psram_init(void)
{
    hal_mtd_t *mtd = hal_mtd_open("psram");
    if (mtd == NULL) {
        return -1;
    }
    if (hal_mtd_ioctl(mtd, PSRAM_CMD_MEMORY_MAPPED, 1) != 0) {
        return -2;
    }
    if (heap_add(kernel_heap, (char *)PSRAM_BASE_ADDR, PSRAM_DEVICE_SIZE) != 0) {
        return -3;
    }

    return 0;
}

MODULE_INIT(postboard, __drv_psram_init);

#endif
